

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The interface module &mdash; pyamp v1.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="pyamp v1.2 documentation" href="../index.html" />
    <link rel="up" title="The interfaces module" href="mod_pyamp_patterns_interfaces.html" />
    <link rel="next" title="The borg module" href="pyamp_patterns_borg.html" />
    <link rel="prev" title="The requiredProperties module" href="pyamp_patterns_interfaces_requiredProperties.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pyamp_patterns_borg.html" title="The borg module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pyamp_patterns_interfaces_requiredProperties.html" title="The requiredProperties module"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="mod_pyamp.html" >The pyamp module</a> &raquo;</li>
          <li><a href="mod_pyamp_patterns.html" >The patterns module</a> &raquo;</li>
          <li><a href="mod_pyamp_patterns_interfaces.html" accesskey="U">The interfaces module</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-pyamp.patterns.interfaces.interface">
<span id="the-interface-module"></span><h1>The interface module<a class="headerlink" href="#module-pyamp.patterns.interfaces.interface" title="Permalink to this headline">¶</a></h1>
<p>The interface module provides a base class which provides a function to
decorate functions in order to label specific functions as <em>interface</em>
functions.</p>
<p>The <tt class="xref py py-class docutils literal"><span class="pre">PassThrough'</span> <span class="pre">class</span> <span class="pre">is</span> <span class="pre">an</span> <span class="pre">implementation</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">:class:`Interface</span></tt>
class which provides the ability to connect a child <a class="reference internal" href="#pyamp.patterns.interfaces.interface.PassThrough" title="pyamp.patterns.interfaces.interface.PassThrough"><tt class="xref py py-class docutils literal"><span class="pre">PassThrough</span></tt></a> object
to a parent <a class="reference internal" href="#pyamp.patterns.interfaces.interface.PassThrough" title="pyamp.patterns.interfaces.interface.PassThrough"><tt class="xref py py-class docutils literal"><span class="pre">PassThrough</span></tt></a> object so that any time the child&#8217;s interface
functions are called, the call is instead redirected to the parent&#8217;s function
of the same name.</p>
<div class="section" id="the-interface-class">
<h2>The Interface class<a class="headerlink" href="#the-interface-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-4193e93e07ccde8a531f66f6d306b9715b12a1cb.png" alt="Inheritance diagram of pyamp.patterns.interfaces.interface.Interface" usemap="#inheritancede4d8a887b" class="inheritance"/>
<map id="inheritancede4d8a887b" name="inheritancede4d8a887b">
<area shape="rect" href="#pyamp.patterns.interfaces.interface.Interface" title="pyamp.patterns.interfaces.interface.Interface" alt="" coords="5,7,315,33"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.patterns.interfaces.interface.Interface">
<em class="property">class </em><tt class="descclassname">pyamp.patterns.interfaces.interface.</tt><tt class="descname">Interface</tt><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#Interface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.Interface" title="Permalink to this definition">¶</a></dt>
<dd><p>The Interface class provides to ability to identify specific class
functions to be &#8216;interface&#8217; functions.</p>
<p>This class contains a class property called InterfaceProperty which defines
the name of the property used to identify interface functions.</p>
<p>This class provides a <a class="reference internal" href="#pyamp.patterns.interfaces.interface.Interface.interface" title="pyamp.patterns.interfaces.interface.Interface.interface"><tt class="xref py py-func docutils literal"><span class="pre">interface()</span></tt></a> function which uses the
InterfaceProperty property to create an implementation specific decorator
which can be used to decorate functions that should identified as interface
functions.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Example</span><span class="p">(</span><span class="n">Interface</span><span class="p">):</span>
    <span class="n">InterfaceProperty</span> <span class="o">=</span> <span class="s">&quot;ExampleInterfaceProperty&quot;</span>

    <span class="nd">@Example.interface</span>
    <span class="k">def</span> <span class="nf">testPrint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
        <span class="k">print</span> <span class="s">&quot;Message:&quot;</span><span class="p">,</span> <span class="n">message</span>
</pre></div>
</div>
<p>This the above example the <tt class="xref py py-func docutils literal"><span class="pre">testPrint()</span></tt> function has been decorated
and is thus an interface function.</p>
<dl class="method">
<dt id="pyamp.patterns.interfaces.interface.Interface.connect">
<tt class="descname">connect</tt><big>(</big><em>parent</em><big>)</big><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#Interface.connect"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.Interface.connect" title="Permalink to this definition">¶</a></dt>
<dd><p>Connect to a parent&#8217;s interface methods.</p>
<p>Note: This should be overriden by concrete Interfaces</p>
<ul class="simple">
<li>parent &#8211; The parent interface object</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.patterns.interfaces.interface.Interface.getInterfaceFunctions">
<tt class="descname">getInterfaceFunctions</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#Interface.getInterfaceFunctions"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.Interface.getInterfaceFunctions" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a dictionary of the interface function names mapped
to the actual functions.</p>
</dd></dl>

<dl class="classmethod">
<dt id="pyamp.patterns.interfaces.interface.Interface.interface">
<em class="property">classmethod </em><tt class="descname">interface</tt><big>(</big><em>function</em><big>)</big><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#Interface.interface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.Interface.interface" title="Permalink to this definition">¶</a></dt>
<dd><p>A decorator for functions to make them interface functions for
this Interface instance.</p>
<ul class="simple">
<li>function &#8211; The function to decorate</li>
</ul>
</dd></dl>

<dl class="classmethod">
<dt id="pyamp.patterns.interfaces.interface.Interface.isInterface">
<em class="property">classmethod </em><tt class="descname">isInterface</tt><big>(</big><em>obj</em><big>)</big><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#Interface.isInterface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.Interface.isInterface" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine if the given object is an instance of the interface.</p>
<ul class="simple">
<li>obj &#8211; The object</li>
</ul>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-passthrough-class">
<h2>The PassThrough class<a class="headerlink" href="#the-passthrough-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-377a443ede6d938082e1f10c1079e6e9c9fcf57c.png" alt="Inheritance diagram of pyamp.patterns.interfaces.interface.PassThrough" usemap="#inheritance6ca59fe95d" class="inheritance"/>
<map id="inheritance6ca59fe95d" name="inheritance6ca59fe95d">
<area shape="rect" href="#pyamp.patterns.interfaces.interface.Interface" title="pyamp.patterns.interfaces.interface.Interface" alt="" coords="19,7,328,33"/>
<area shape="rect" href="#pyamp.patterns.interfaces.interface.PassThrough" title="pyamp.patterns.interfaces.interface.PassThrough" alt="" coords="5,84,341,111"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.patterns.interfaces.interface.PassThrough">
<em class="property">class </em><tt class="descclassname">pyamp.patterns.interfaces.interface.</tt><tt class="descname">PassThrough</tt><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#PassThrough"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.PassThrough" title="Permalink to this definition">¶</a></dt>
<dd><p>The PassThrough <a class="reference internal" href="#pyamp.patterns.interfaces.interface.Interface" title="pyamp.patterns.interfaces.interface.Interface"><tt class="xref py py-class docutils literal"><span class="pre">Interface</span></tt></a> provides the ability for a child
PassThrough object to connect functions of the same name to the parent&#8217;s
<a class="reference internal" href="#pyamp.patterns.interfaces.interface.Interface" title="pyamp.patterns.interfaces.interface.Interface"><tt class="xref py py-class docutils literal"><span class="pre">Interface</span></tt></a> functions.</p>
<p>When a child class connects to the parent&#8217;s interface functions, all calls
to the child&#8217;s interface functions are instead redirected to the parent&#8217;s
functions of the same name.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Parent</span><span class="p">(</span><span class="n">PassThrough</span><span class="p">):</span>
    <span class="nd">@PassThrough.interface</span>
    <span class="k">def</span> <span class="nf">testPrint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
        <span class="k">print</span> <span class="s">&quot;Parent message:&quot;</span><span class="p">,</span> <span class="n">message</span>

<span class="k">class</span> <span class="nc">Child</span><span class="p">(</span><span class="n">PassThrough</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="n">parent</span> <span class="o">=</span> <span class="n">Parent</span><span class="p">()</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">Child</span><span class="p">()</span>
<span class="n">child</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>

<span class="c"># Prints:</span>
<span class="c">#    &quot;Parent message:&quot;, this is a message</span>
<span class="n">child</span><span class="o">.</span><span class="n">testPrint</span><span class="p">(</span><span class="s">&quot;this is a message&quot;</span><span class="p">)</span>
</pre></div>
</div>
<dl class="method">
<dt id="pyamp.patterns.interfaces.interface.PassThrough.connect">
<tt class="descname">connect</tt><big>(</big><em>parent</em><big>)</big><a class="reference internal" href="../_modules/pyamp/patterns/interfaces/interface.html#PassThrough.connect"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.patterns.interfaces.interface.PassThrough.connect" title="Permalink to this definition">¶</a></dt>
<dd><p>Connect the child to the parent&#8217;s interface functions.</p>
<ul class="simple">
<li>parent &#8211; The parent Interface</li>
</ul>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The interface module</a><ul>
<li><a class="reference internal" href="#the-interface-class">The Interface class</a></li>
<li><a class="reference internal" href="#the-passthrough-class">The PassThrough class</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="pyamp_patterns_interfaces_requiredProperties.html"
                        title="previous chapter">The requiredProperties module</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="pyamp_patterns_borg.html"
                        title="next chapter">The borg module</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/_generated/pyamp_patterns_interfaces_interface.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pyamp_patterns_borg.html" title="The borg module"
             >next</a> |</li>
        <li class="right" >
          <a href="pyamp_patterns_interfaces_requiredProperties.html" title="The requiredProperties module"
             >previous</a> |</li>
        <li><a href="../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="mod_pyamp.html" >The pyamp module</a> &raquo;</li>
          <li><a href="mod_pyamp_patterns.html" >The patterns module</a> &raquo;</li>
          <li><a href="mod_pyamp_patterns_interfaces.html" >The interfaces module</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Brett Ponsler.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
    </div>
  </body>
</html>